﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Battle
{
    /*
     * Ability System Design:
     * A ability is a speller and targets combined with AbilityBehaviors.
     * Programmer needs to implement a abstract behavior like attach effect AttachEffect.
     */
    public class Ability
    {
        public IEntity Speller { get; set; }
        public List<IEntity> Targets { get; set; }
        public string Name { get; }

        private List<IAbilityBehavior> behaviors;

        public Action OnAbilitySpell { private get; set; }
        public Ability(IEntity speller, IEnumerable<IEntity> targets, AbilityDef abilityDef)
        {
            Speller = speller;
            Targets = new List<IEntity>(targets);
            Name = abilityDef.name;
            behaviors = new List<IAbilityBehavior>(abilityDef.behaviors);
        }

        public void Spell()
        {
            if (OnAbilitySpell != null) OnAbilitySpell();
            foreach (var behavior in behaviors)
            {
                behavior.Apply(Speller, Targets);
            }
        }
    }
}
